package com.example.score;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class MyViewModel extends ViewModel {
    private MutableLiveData<Integer> ateamescore;
    private MutableLiveData<Integer> bteamescore;
    private int aBack,bBack;
    public MutableLiveData<Integer> getAteamescore() {
        if (ateamescore == null){
            ateamescore = new MutableLiveData<>();
            ateamescore.setValue(0);
        }
        return ateamescore;
    }

    public MutableLiveData<Integer> getBteamescore() {
        if (bteamescore == null){
            bteamescore = new MutableLiveData<>();
            bteamescore.setValue(0);
        }
        return bteamescore;
    }
    public void ATeamAdd(int p){
        aBack =ateamescore.getValue();
        bBack = bteamescore.getValue();
        ateamescore.setValue(ateamescore.getValue()+p);
    }
    public void BTeamAdd(int p){
        aBack =ateamescore.getValue();
        bBack = bteamescore.getValue();
        bteamescore.setValue(bteamescore.getValue()+p);
    }
    public void reset(){
        aBack =ateamescore.getValue();
        bBack = bteamescore.getValue();
        ateamescore.setValue(0);
        bteamescore.setValue(0);
    }
    public void undo(){
        ateamescore.setValue(aBack);
        bteamescore.setValue(bBack);
    }
}
